{extend name="admin@index_layout"/}
{block name="main"}
<div class="layui-card">
    <div class="layui-card-header">添加推荐位</div>
    <div class="layui-card-body">
        <blockquote class="layui-elem-quote">未选择模型与栏目，则全站通用；如选择模型未选择栏目，则该推荐位在该模型下通用。</blockquote>
        <form class="layui-form form-horizontal" action="" method="post">
            <div class="layui-form-item">
                <label class="layui-form-label">推荐位名称</label>
                <div class="layui-input-inline">
                    <input type="text" name="name" lay-verify="name" placeholder="推荐位名称" class="layui-input" required  value="{$data['name']}">
                </div>
            </div>
            <div class="layui-form-item web_list">
                <label class="layui-form-label">所属模型</label>
                <div class="layui-input-inline">
                    <select name="modelid" lay-filter="modelid">
                        <option value="0">请选择模型</option>
                        {volist name="modelinfo" id="vo"}
                        <option value="{$key}" {if $key == $data['modelid']}selected{/if}>{$vo}</option>
                        {/volist}
                    </select>
                </div>
            </div>
            <div class="layui-form-item web_list">
                <label class="layui-form-label">所属栏目</label>
                <div class="layui-input-inline" id="load_catid">
                    {php}echo \util\Form::select_category($data['catid'], 'name=catid', '作为顶级栏目', $data['modelid']);{/php}
                </div>
            </div>
            <input name="id" value="{$data['id']}" type="hidden" />
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn ajax-post" lay-submit lay-filter="*" target-form="form-horizontal">立即提交</button>
                    <button class="layui-btn layui-btn-normal" onClick="javascript :history.back(-1);">返回</button>
                </div>
            </div>
        </form>
    </div>
</div>
{/block}
{block name="script"}
<script type="text/javascript" src="__STATIC__/admin/js/common.js"></script>
<script type="text/javascript">
layui.use(['layer', 'form'], function() {
    var layer = layui.layer,
        form = layui.form;
        form.on('select(modelid)', function(data){
            $.get('{:url("cms/position/public_category_load")}'+'?modelid='+data.value,function(data){
                $('#load_catid').html(data);
                form.render('select'); //刷新select选择框渲染
            });
            //console.log(data.value);
        });
});
</script>
{/block}